<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增号源</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .form-control:focus {
            border-color: #28a745;
            box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
        }
        .btn-success {
            background-color: #28a745;
            border-color: #28a745;
        }
        .btn-success:hover {
            background-color: #218838;
            border-color: #1e7e34;
        }
    </style>
</head>
<body>

<div class="container mt-5">
    <h2>新增号源</h2>
    <form id="addScheduleForm">
        <div class="mb-3">
            <label for="doctorId" class="form-label">医生ID</label>
            <input type="number" class="form-control" id="doctorId" name="doctorId" required>
        </div>
        <div class="mb-3">
            <label for="date" class="form-label">日期</label>
            <input type="date" class="form-control" id="date" name="date" required>
        </div>
        <div class="mb-3">
            <label for="period" class="form-label">时间段</label>
            <select class="form-select" id="period" name="period" required>
                <option value="1">上午</option>
                <option value="2">下午</option>
            </select>
        </div>
        <div class="mb-3">
            <label for="totalNumber" class="form-label">总号数</label>
            <input type="number" class="form-control" id="totalNumber" name="totalNumber" min="1" required>
        </div>
        <div class="mb-3">
            <label for="availableNumber" class="form-label">可用号数</label>
            <input type="number" class="form-control" id="availableNumber" name="availableNumber" min="0" required>
        </div>
        <div class="mb-3">
            <label for="price" class="form-label">价格</label>
            <input type="number" class="form-control" id="price" name="price" min="0" step="0.01" required>
        </div>
        <div class="mb-3">
            <label for="status" class="form-label">状态</label>
            <select class="form-select" id="status" name="status">
                <option value="1" selected>可用</option>
                <option value="0">不可用</option>
            </select>
        </div>
        <div class="mb-3">
            <label for="description" class="form-label">备注</label>
            <textarea class="form-control" id="description" name="description" rows="3"></textarea>
        </div>
        <button type="submit" class="btn btn-success">提交</button>
    </form>
</div>

<script src="/js/jquery.min.js"></script>
<script>
    $(document).ready(function () {
        $('#addScheduleForm').on('submit', function (e) {
            e.preventDefault();

            const schedule = {
                doctorId: parseInt($('#doctorId').val()),
                date: $('#date').val(),
                period: $('#period').val(),
                totalNumber: parseInt($('#totalNumber').val()),
                availableNumber: parseInt($('#availableNumber').val()),
                price: parseFloat($('#price').val()),
                status: parseInt($('#status').val()),
                description: $('#description').val()
            };

            $.ajax({
                url: "/admins/addSchedule",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(schedule),
                success: function () {
                    alert("号源添加成功");
                    window.location.href = "/scheduleList";
                },
                error: function () {
                    alert("添加失败");
                }
            });
        });
    });
</script>

</body>
</html>